<?php $this->load->view('layout/header_data_form');?>
<?php $this->load->view('layout/logo');?>

<script>
	function year_university(year_birth,gender,year_university)
	{
		var gen	=	$("#"+gender).val();
		//alert(gen);
		$.ajax({
			   type: "POST",
			   url: "<?php echo base_url().'education/year_university'?>",
			   data: "year_birth="+$("#"+year_birth).val()+"&gender="+gen,
			   success: function(msg){
			     $('#'+year_university).val(msg);
			   }
		});
	}
</script>
<div id="wrap">
  <form id="form1" name="form1" method="post" action="">
    <table border="0" cellpadding="5" cellspacing="0">
      <tr>
        <td width="500" align="left" valign="top"><table border="0" cellpadding="7" cellspacing="0">
          <tr>
            <td width="160" align="right"><strong>Number of Children:</strong></td>
            <td><select name="child" class="field" id="child" onchange="javascript:ShowDiv();">
                <?php for($i=0; $i<=5; $i++):?>
                <option <?php echo(count($row)==$i ? 'selected="selected"' : '');?> value="<?php echo $i;?>"><?php echo $i;?></option>
                <?php endfor;?>
            </select></td>
          </tr>
          <tr>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
        
          <div id="one" style="display:<?php echo(count($row)>=1 ? "block" : "none");?>">
    <table border="0" cellpadding="7" cellspacing="0">
      <tr>
        <td align="right"><strong>[1]</strong></td>
        <td align="right" width="130" ><strong>Child:</strong></td>
        <td><select onchange="year_university('birth1','select1','years1')" name="select1" class="field" id="select1">
          <option <?php echo($row && isset($row[0]) && $row[0]['gender']== 'Male' ? "selected='selected'" : "");?> value="Male" selected="selected">Male</option>
          <option <?php echo($row && isset($row[0]) && $row[0]['gender'] == 'Female' ? "selected='selected'" : "");?> value="Female">Female</option>
                        </selec >
          <input type="hidden" name="id1" value="<?php echo($row && isset($row[0]) ? $row[0]['id'] : '');?>"/>
        </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Date of Birth:</strong></td>
        <td><input name="birth1" id="birth1" type="text" value="<?php echo($row && isset($row[0]) ? convert_dmysql_date($row[0]['date_of_birth']) : "");?>" class="field" id="textfield" onfocus="if(this.value=='MM/DD/YYYY') this.value='';" onblur="year_university('birth1','select1','years1')" value="MM/DD/YYYY" /></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Years to University:</strong></td>
        <td><input  name="years1" value="<?php echo($row && isset($row[0]) ? $row[0]['years_to_university'] : "");?>" type="text" class="field" id="years1" size="50" /></td>
      </tr>
    </table>
    </div>
    
    <div id="two" style="display:<?php echo(count($row)>=2 ? "block" : "none");?>">
    <table border="0" cellpadding="7" cellspacing="0">
      <tr>
        <td align="right"><strong>[2]</strong></td>
        <td align="right" width="130" ><strong>Child:</strong></td>
        <td><select name="select2" class="field" id="select2" onchange="year_university('birth2','select2','years2')">
          <option <?php echo($row && isset($row[1]) && $row[1]['gender'] == 'Male' ? "selected='selected'" : "");?> value="Male" selected="selected">Male</option>
          <option <?php echo($row && isset($row[1]) && $row[1]['gender'] == 'Female' ? "selected='selected'" : "");?> value="Female">Female</option>
                        </select>
       		<input type="hidden" name="id2" value="<?php echo($row && isset($row[1]) ? $row[1]['id'] : '');?>"/>                 
       </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Date of Birth:</strong></td>
        <td><input name="birth2" id="birth2" type="text" value="<?php echo($row && isset($row[1]) ? convert_dmysql_date($row[1]['date_of_birth']) : "");?>" class="field" id="textfield" onfocus="if(this.value=='MM/DD/YYYY') this.value='';" onblur="year_university('birth2','select2','years2')" value="DD/MM/YYYY" /></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Years to University:</strong></td>
        <td><input  name="years2" value="<?php echo($row && isset($row[1]) ? $row[1]['years_to_university'] : "");?>" type="text" class="field" id="years2" size="50" /></td>
      </tr>
    </table>
    </div>
    
    <div id="three" style="display:<?php echo(count($row)>=3 ? "block" : "none");?>">
    <table border="0" cellpadding="7" cellspacing="0">
      <tr>
        <td align="right"><strong>[3]</strong></td>
        <td align="right" width="130" ><strong>Child:</strong></td>
        <td><select name="select3" class="field" id="select3" onchange="year_university('birth3','select3','years3')">
          <option <?php echo($row && isset($row[2]) && $row[2]['gender'] == 'Male' ? "selected='selected'" : "");?> value="Male" selected="selected">Male</option>
          <option <?php echo($row && isset($row[2]) && $row[2]['gender'] == 'Female' ? "selected='selected'" : "");?> value="Female">Female</option>
                        </select>
                        <input type="hidden" name="id3" value="<?php echo($row && isset($row[2]) ? $row[2]['id'] : '');?>"/>
                        </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Date of Birth:</strong></td>
        <td><input name=birth3 id="birth3" type="text" value="<?php echo($row && isset($row[2]) ? convert_dmysql_date($row[2]['date_of_birth']) : "");?>" class="field" id="textfield" onfocus="if(this.value=='MM/DD/YYYY') this.value='';" onblur="year_university('birth3','select3','years3')" value="DD/MM/YYYY" /></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Years to University:</strong></td>
        <td><input  name="years3"  value="<?php echo($row && isset($row[2]) ? $row[2]['years_to_university'] : "");?>" type="text" class="field" id="years3" size="50" /></td>
      </tr>
    </table>
    </div>
    
    <div id="four" style="display:<?php echo(count($row)>=4 ? "block" : "none");?>">
    <table border="0" cellpadding="7" cellspacing="0">
      <tr>
        <td align="right"><strong>[4]</strong></td>
        <td align="right" width="130" ><strong>Child:</strong></td>
        <td><select name="select4" class="field" id="select4" onchange="year_university('birth4','select4','years4')">
          <option <?php echo($row && isset($row[3]) && $row[3]['gender'] == 'Male' ? "selected='selected'" : "");?> value="Male" selected="selected">Male</option>
          <option <?php echo($row && isset($row[3]) && $row[3]['gender'] == 'Female' ? "selected='selected'" : "");?> value="Female">Female</option>
                        </select>
                        <input type="hidden" name="id4" value="<?php echo($row && isset($row[3]) ? $row[3]['id'] : '');?>"/>
                        </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Date of Birth:</strong></td>
        <td><input value="<?php echo($row && isset($row[3]) ? convert_dmysql_date($row[3]['date_of_birth']) : "");?>" name="birth4" id="birth4" type="text" class="field" id="textfield" onfocus="if(this.value=='MM/DD/YYYY') this.value='';" onblur="year_university('birth4','select4','years4')" value="MM/DD/YYYY" /></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Years to University:</strong></td>
        <td><input  name="years4"  value="<?php echo($row && isset($row[3]) ? $row[3]['years_to_university'] : "");?>" type="text" class="field" id="years4" size="50" /></td>
      </tr>
    </table>
    </div>
    
    <div id="five" style="display:<?php echo(count($row)>=5 ? "block" : "none");?>">
    <table border="0" cellpadding="7" cellspacing="0">
      <tr>
        <td align="right"><strong>[5]</strong></td>
        <td align="right" width="130" ><strong>Child:</strong></td>
        <td><select name="select5" class="field" id="select5" onchange="year_university('birth5','select5','years5')">
          <option <?php echo($row && isset($row[4]) && $row[4]['gender'] == 'Male' ? "selected='selected'" : "");?> value="Male" selected="selected">Male</option>
          <option <?php echo($row && isset($row[4]) && $row[4]['gender'] == 'Female' ? "selected='selected'" : "");?> value="Female">Female</option>
                        </select>
                        <input type="hidden" name="id5" value="<?php echo($row && isset($row[4]) ? $row[4]['id'] : '');?>"/>
                        </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Date of Birth:</strong></td>
        <td><input name="birth5" id="birth5" value="<?php echo($row && isset($row[4]) ? convert_dmysql_date($row[4]['date_of_birth']) : "");?>" type="text" class="field" id="textfield" onfocus="if(this.value=='MM/DD/YYYY') this.value='';" onblur="year_university('birth5','select5','years5')" value="DD/MM/YYYY" /></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td align="right"><strong>Years to University:</strong></td>
        <td><input  name="years5" value="<?php echo($row && isset($row[4]) ? $row[4]['years_to_university'] : "");?>" type="text" class="field" id="years5" size="50" /></td>
      </tr>
    </table>
    </div>
        
          <table border="0" cellpadding="7" cellspacing="0">
            <tr>
              <td width="158"  align="left">&nbsp;</td>
              <td>
              <input type="submit" class="large button green" value="Calculate" />
              <input type="hidden" value="0" name="submit"/>
              </td>
            </tr>
          </table>          </td>
      </tr>
      <tr>
        <td align="left" valign="top">
        
                     <div id="graph" style="display:<?php echo($row && count($row) > 0 ? 'block' : 'none')?>">
<br />
<br />
</form>
 
 <?php //Chart?>
 <?php $this->load->view('education/chart');?>
 <?php //End chart?>
 
 		<form method="post" action="">
            <table border="0" cellpadding="7" cellspacing="0">
	              <tr>
	                <td align="left"><strong>Explanation:</strong></td>
	              </tr>
	              <tr>
	                <td align="left"><textarea name="textfield3" cols="60" rows="6" class="field" id="textfield3"><?php echo(isset($exp) && $exp ? $exp->explanation : '');?></textarea></td>
	              </tr>
	              <tr>
	                <td align="right">
	                	<input type="submit" class="large button red" value="Submit"/>
	                	<input type="hidden" value="1" name="submit"/>
	                </td>
	              </tr>
	          </table>
          </form>

<br />
</div>   
        
        </td>
      </tr>
    </table>
   <a href="JavaScript:window.close();"><img src="images/cwindow.jpg" alt="Close Window" width="82" height="15" border="0" /></a>
    
  

<script language="javascript"> 
	function ShowDiv(){
		//safeToggleFieldDisplay('one');
		//safeToggleFieldDisplay('two');
		//safeToggleFieldDisplay(document.getElementById('three'),'none');
		//safeToggleFieldDisplay(document.getElementById('four'),'none');
 
		var dropdown = document.getElementById("child");
		var index = dropdown.selectedIndex;
		var selectedDIV = dropdown.options[index].value;
		safeToggleFieldDisplay(selectedDIV);
	}
	
	function safeToggleFieldDisplay(field){
		try{
			 if(field == '0'){
				document.getElementById('one').style.display = 'none';
				document.getElementById('two').style.display = 'none';
				document.getElementById('three').style.display = 'none';
				document.getElementById('four').style.display = 'none';
				document.getElementById('five').style.display = 'none';
				document.getElementById('submitbut').style.display = 'none';
			}
			else if(field == '1'){
				document.getElementById('one').style.display = 'block';
				document.getElementById('two').style.display = 'none';
				document.getElementById('three').style.display = 'none';
				document.getElementById('four').style.display = 'none';
				document.getElementById('five').style.display = 'none';
				document.getElementById('submitbut').style.display = 'block';
			}
			else if(field == '2'){
				document.getElementById('one').style.display = 'block';
				document.getElementById('two').style.display = 'block';
				document.getElementById('three').style.display = 'none';
				document.getElementById('four').style.display = 'none';
				document.getElementById('five').style.display = 'none';
				document.getElementById('submitbut').style.display = 'block';
			} 
			else if(field == '3'){
				document.getElementById('one').style.display = 'block';
				document.getElementById('two').style.display = 'block';
				document.getElementById('three').style.display = 'block';
				document.getElementById('four').style.display = 'none';
				document.getElementById('five').style.display = 'none';
				document.getElementById('submitbut').style.display = 'block';
			} 
			else if(field == '4'){
				document.getElementById('one').style.display = 'block';
				document.getElementById('two').style.display = 'block';
				document.getElementById('three').style.display = 'block';
				document.getElementById('four').style.display = 'block';
				document.getElementById('five').style.display = 'none';
				document.getElementById('submitbut').style.display = 'block';
			} 
			else if(field == '5'){
				document.getElementById('one').style.display = 'block';
				document.getElementById('two').style.display = 'block';
				document.getElementById('three').style.display = 'block';
				document.getElementById('four').style.display = 'block';
				document.getElementById('five').style.display = 'block';
				document.getElementById('submitbut').style.display = 'block';
			} 
		}
		catch(exception){
			//no handling - just preventing page explosions
		}
	}
 
	//ShowDiv();
</script> 
  
</div>
<?php $this->load->view('layout/footer_data_form');?>